"""
4. 按以下要求写程序
    1. echo_server.py 程序同时响应多个客户端的请求，接收客户端的数据，在数据前面加上 "received: "，然后返回给客户端
    2. echo_client.py 程序持续地给服务端发送当前时间，每发一次就睡眠1秒钟
"""
from socket import *
from multiprocessing import Process

def prcFunc(sock):
    while True:
        data = sock.recv(2048)
        print(data.decode())
        if not data:
            sock.close()
            break
        data = b'receieved: '+ data
        sock.send(data)
if __name__ == '__main__':
    serSocket = socket(AF_INET, SOCK_STREAM)
    addr = ("", 3301)
    serSocket.bind(addr)
    serSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    serSocket.listen(5)
    while True:
        cliSocket,cliAddr = serSocket.accept()
        p = Process(target=prcFunc,args=(cliSocket,))
        p.start()
        cliSocket.close()